package Midium;

//3.无重复字符的最长子串
public class Solution3 {
    public static int lengthOfLongestSubstring(String s) {
        if(s.length()==0)
            return 0;
        int maxLength = 1;
        int i, j;
        for (i = 0, j = i + 1; j < s.length(); ) {
            int k;
            for(k = i; k <j;){
                if(s.charAt(k)!=s.charAt(j))
                    k++;
                else break;
            }
            if(k==j) {
                j++;
                maxLength = Math.max(maxLength, j - i);
            }else {
                i++;
                //优化：因为i到j不重复，所以i+1到j也不重复，无需重新到i+1开始判断
                //j=i+1;
            }
        }
        return maxLength;
    }

    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("abcabcbb"));
    }
}
